package settings

import (
	"fmt"
	"path"
	"strings"
)

const (
	//// for http server
	// SitePort = 29999
	SitePort = 19999
)

const (
	// for static files
	Dir_StaticFile = "/data/files" //fs
	Dir_Videos     = "videos"
	Dir_MORE       = "more_and_more"

	Dir_others_store = "others_store"

	UrlPath_StaticFile      = "/files"     //url path
	UrlPath_TvOthers        = "/tv_others" //url path 解析其他 集合.
	URL_PUSHED_VODID_PREFIX = "/tv_others/category/pushed/1/"

	// // NewCatesID_Starter = 9999999
	// NewCatesID_MORE0 = "more0"
	// NewCatesID_MORE1 = "more1"
	// NewCatesID_PUSH  = "push"
)

var (
	NewCates_MORES  = []string{"more_0", "more_1"}
	NewCates_PUSH = "more_push"
	// 格式 http://v3.tv.server.lan:19999
	//   改变这 可以改变 docker 外部的 端口.
	//    从而重定向到docker 内的 19999
	SiteDomain = "http://v3.tv.server.lan:19999"
)

var (
	// for /api.json
	PATH_API_JSON = path.Join(UrlPath_StaticFile, "/v3/box1.json")
	FAVICON_TV    = path.Join(UrlPath_StaticFile, "/v3/favicontv.ico")
	FAVICON       = path.Join(UrlPath_StaticFile, "/v3/favicon.ico")

	// for /api/
	FallbackURL_Path string = path.Join(UrlPath_StaticFile, "/v3/fallback")
)

var (
	UrlPath_VideoRoot = path.Join(UrlPath_StaticFile, Dir_Videos)
	// noTv         = path.Join(videoUrlRoot, "noTv.mp4")
	seasons = [...]string{
		"noTv.mp4", //占位符, index 对齐 正整数
		"season01.mp4",
		"season02.mp4",
		"season03.mp4",
		"season04.mp4",
		"season05.mp4",
		"season06.mp4",
		"season07.mp4",
		"season08.mp4",
		"season09.mp4",
		"season10.mp4",
		"season11.mp4",
		"season12.mp4",
		"season13.mp4",
		"season14.mp4",
		"season15.mp4",
		"season16.mp4",
		"season17.mp4",
		"season18.mp4",
		"season19.mp4",
		"season20.mp4",
		"season21.mp4",
		"season22.mp4",
		"season23.mp4",
		"season24.mp4",
		"season25.mp4",
		"season26.mp4",
		"season27.mp4",
		"season28.mp4",
		"season29.mp4",
		"season30.mp4",
		"season_more.mp4",
	}
)

func getUrl(p string) string {
	// pre := "http"
	// post := ""
	// if SitePort == 443 {
	// 	pre = "https"
	// } else if SitePort != 80 {
	// 	post = fmt.Sprintf(":%d", SitePort)
	// }

	if len(p) > 0 {
		p = path.Join("/", p) // 可以除掉重复的/  a//b -> a/b
	}

	return fmt.Sprintf("%s%s", SiteDomain, p)

	// return fmt.Sprintf("%s://%s%s%s", pre, SiteDomain, post, path)
}

func GetNoTv() string {
	return GetSeasonUrlI(0)
}

func getURL_StaticFile(p string) string {
	if len(p) > 0 && !strings.HasPrefix(p, "/") {
		//相对路径
		p = path.Join(UrlPath_StaticFile, p)
	}
	return getUrl(p)
}

func GetSeasonUrlI(i int) string {
	return getUrl(getURL_SeasonPathI(i))
}

func getURL_SeasonPathI(i int) string {
	if i >= len(seasons) {
		i = len(seasons) - 1
	}
	return path.Join(UrlPath_VideoRoot, "oo", seasons[i])
}

// http://v3.tv.server.lan:19999/files/videos/oo/noTv.mp4
